#include "StdAfx.h"
#include "DActorFactory.h"
#include <fstream>
#include "../DGlobals.h"
#include "../Engine/DAnimation.h"
#include "../Engine/DIResourceManager.h"
#include "../Game/DGame.h"
#include "DIActor.h"
#include "DPlayer.h"
#include "DBackground.h"
#include "DEnemy.h"
#include "Weapons/DBulletFirebolt.h"

DActorFactory::DActorFactory(void)
{
}

DActorFactory::~DActorFactory(void)
{
}

DActorFactory& DActorFactory::instance()
{
	static DActorFactory inst;
	return inst;
}

boost::shared_ptr<DPlayer> DActorFactory::createPlayer(boost::shared_ptr<DGame> game)
{
	boost::shared_ptr<DPlayer> player(new DPlayer(game));

	player->addAnimation("Flying", game->globalResourceManager()->animation("Player/Flying"));
	player->setCurrentAnimation("Flying");
	return player;
}

boost::shared_ptr<DBackground> DActorFactory::createBackground(const std::string& backName, boost::shared_ptr<DIResourceManager> resManager)
{
	boost::shared_ptr<DBackground> back(new DBackground(resManager->animation(backName)));
	return back;
}

boost::shared_ptr<DIActor> DActorFactory::createEnemy(boost::shared_ptr<DGame> game, const std::string& strEnemyType, float xStart, float yStart, 
		boost::shared_ptr<DIResourceManager> resManager)
{
	if(strEnemyType == "Enemy1")
	{
		boost::shared_ptr<DEnemy> enemy(new DEnemy(game));
		enemy->setPos(vec2(xStart, yStart));
		enemy->addAnimation("Flying", resManager->animation("Enemies/Enemy1/Flying"));
		enemy->setCurrentAnimation("Flying");
		return enemy;
	}

	return boost::shared_ptr<DIActor>();
}

boost::shared_ptr<DIActor> DActorFactory::createBullet(boost::shared_ptr<DGame> game, boost::shared_ptr<DIActor> source, 
                                                       const std::string& strBulletType, const Weapons::BulletCreationParams& bcParams)
{
    if(strBulletType == "Firebolt")
    {
        boost::shared_ptr<Weapons::DIBullet> bullet(new Weapons::DBulletFirebolt(game, source));
        bullet->setPos(vec2(bcParams.startX, bcParams.startY));
        bullet->addAnimation("Firebolt", game->globalResourceManager()->animation("Bullets/Firebolt"));
        bullet->setCurrentAnimation("Firebolt");
        return bullet;
    }

    return boost::shared_ptr<DIActor>();
}